#pragma once

#include "SipInviteSession.hpp"
#include "SipRegisterSession.hpp"
#include "SipSubscribeSession2.hpp"
#include "SipTranSession.hpp"

using namespace wtsip;

class CResipTesterDlg;


class CSipRealPlayHandler :public CSipRealPlayHandle
{
public:

    CSipRealPlayHandler(CResipTesterDlg& dlg, CSipInviteSession& invs, std::list<CSipRealPlayHandler*>& list);

    ~CSipRealPlayHandler(void);

    void start(std::string& body);

    void shutdown();

    void ptzControl(std::string& body);

    /////////////////////////////////////////////////////////////////

    virtual bool onCancel(SipMessage& msg, CSipInviteSession& invs);

    virtual bool onCanceled(SipMessage& msg, CSipInviteSession& invs);

    virtual bool onPtzControl(SipMessage& msg, CSipInviteSession& invs);

    virtual bool onConnected(SipMessage& msg, CSipInviteSession& invs);

    virtual bool onDisconnected(CSipInviteSession& invs);

    virtual bool onTerminated(SipMessage& msg, CSipInviteSession& invs);

    virtual bool onTerminate(SipMessage& msg, CSipInviteSession& invs);

    virtual bool onSuccess(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onFailed(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onTrying(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onDestroy(CSipSessionBase& sb);

private:

    CResipTesterDlg& m_dlg;

    std::list<CSipRealPlayHandler*>& m_list;

    CSipInviteSession& m_invSession;
};


class CSipRegisterHandler: public CSipRegisterHandle
{
public:
    CSipRegisterHandler(
        CResipTesterDlg& dlg, 
        CSipRegisterSession& regs, 
        std::list<CSipRegisterHandler*>& list);

    ~CSipRegisterHandler();

    void start(std::string& body);

    void stop();

    bool regSuccess();

    const resip::Uri& getRemoteUri();

    ////////////////////////////////////

    virtual bool onSuccess(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onFailed(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onTrying(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onDestroy(CSipSessionBase& sb);

    virtual bool onDisconnected(CSipRegisterSession& regs);

    virtual bool onRejected(SipMessage& msg, CSipRegisterSession& regs);

private:

    bool m_regSuccess;

    std::list<CSipRegisterHandler*>& m_list;

    CResipTesterDlg& m_dlg;

    CSipRegisterSession& m_regSession;
};


class CSipSubscribeHandler :public CSipSubscribe2Handle
{
public:
    CSipSubscribeHandler(
        CResipTesterDlg& dlg, 
        CSipSubscribeSession2& subs, 
        std::list<CSipSubscribeHandler*>& list);

    ~CSipSubscribeHandler();

    void subscribe(std::string& body);

    void unsubscribe(std::string& body);

    void notify(std::string& body);

protected:
    /////////////////// handle methods ////////////////////

    virtual bool onSubscribe(SipMessage& msg, CSipSubscribeSession2& subs);

    virtual bool onUnsubscribe(SipMessage& msg, CSipSubscribeSession2& subs);

    virtual bool onNotify(SipMessage& msg, CSipSubscribeSession2& subs);

    virtual bool onSuccess(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onFailed(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onTrying(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onDestroy(CSipSessionBase& sb);

private:

    CResipTesterDlg& m_dlg;

    CSipSubscribeSession2& m_subSession;

    std::list<CSipSubscribeHandler*>& m_list;
};


class CSipSessionHandler: public CSipSessionHandle
{
public:
    CSipSessionHandler(
        CResipTesterDlg& dlg, 
        //CSipTranSession& regs, 
        std::list<CSipSessionHandler*>& list);

    ~CSipSessionHandler();

    //resip::Uri& getRemoteUri();

protected:
    ////////////////////////////////////

    virtual bool onSuccess(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onFailed(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onTrying(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onDestroy(CSipSessionBase& sb);

private:

    std::list<CSipSessionHandler*>& m_list;

    CResipTesterDlg& m_dlg;

    //CSipTranSession& m_regSession;
};



class CSipB2bSessionHandler: public CSipSessionHandle
{
public:
    CSipB2bSessionHandler(
        CSipTranSession& callee, 
        std::list<CSipB2bSessionHandler*>& list);

    ~CSipB2bSessionHandler();

    ////////////////////////////////////

    virtual bool onSuccess(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onFailed(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onTrying(SipMessage& msg, CSipSessionBase& sb);

    virtual bool onDestroy(CSipSessionBase& sb);

private:

    std::list<CSipB2bSessionHandler*>& m_list;

    //CResipTesterDlg& m_dlg;

    CSipTranSession& m_callee;
};


